import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  ParseIntPipe,
  Query,
} from '@nestjs/common';
import { TagService } from './tag.service';
import { CreateTagDto } from './dto/create-tag.dto';
import { UpdateTagDto } from './dto/update-tag.dto';
import { ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';

@ApiTags('标签管理')
@Controller('tag')
export class TagController {
  constructor(private readonly tagService: TagService) {}

  @ApiOperation({ summary: '新增标签' })
  @Post()
  create(@Body() createTagDto: CreateTagDto) {
    return this.tagService.create(createTagDto);
  }

  @ApiOperation({ summary: '分页查询分类列表' })
  @ApiQuery({
    name: 'page',
    type: Number,
    description: '当前页码',
    required: true,
    example: 1,
  })
  @ApiQuery({
    name: 'pageSize',
    type: Number,
    description: '分页大小',
    required: true,
    example: 10,
  })
  @ApiQuery({
    name: 'name',
    type: String,
    description: '分类名称',
    required: false,
    example: '',
  })
  @ApiQuery({
    name: 'keywords',
    type: String,
    description: '关键词',
    required: false,
    example: '',
  })
  @ApiQuery({
    name: 'sortFeild',
    type: String,
    description: '排序字段',
    required: false,
    example: '',
  })
  @ApiQuery({
    name: 'sort',
    type: String,
    description: '排序方式[DESC:升序]、[ASC降序]',
    required: false,
    example: '',
  })
  @Get()
  findAll(
    @Query('page', new ParseIntPipe()) page = 1,
    @Query('pageSize', new ParseIntPipe()) pageSize = 10,
    @Query('name') name?: string,
    @Query('keywords') keywords?: string,
    @Query('sortFeild') sortFeild?: string,
    @Query('sort') sort?: string,
  ) {
    return this.tagService.findAll({
      page,
      pageSize,
      name,
      keywords,
      sortFeild,
      sort,
    });
  }

  @ApiOperation({ summary: '查询所有标签列表' })
  @Get('list')
  findList() {
    return this.tagService.findAllList();
  }

  @ApiOperation({ summary: '查询标签详情' })
  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.tagService.findOne(id);
  }

  @ApiOperation({ summary: '更新标签信息' })
  @Patch(':id')
  update(@Param('id') id: string, @Body() updateTagDto: UpdateTagDto) {
    return this.tagService.update(id, updateTagDto);
  }

  @ApiOperation({ summary: '删除标签' })
  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.tagService.remove(id);
  }
}
